package com.testMvc;

import com.alibaba.fastjson.JSONObject;
import com.core.netty.http.work.HttpMyReponse;
import com.core.netty.http.work.HttpMyRequest;
import com.core.netty.http.work.HttpMySerlvet;
import com.core.netty.http.work.MySerlvetUrl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@MySerlvetUrl("/testser")
public class NettySerlvetTest extends HttpMySerlvet {
    @Override
    public void domain(HttpMyRequest req, HttpMyReponse rep) {
        System.out.println(req.getParameter("abc"));
        System.out.println(req.getRemoteHost() + " ds "+req.getPort());
        System.out.println(req.getUrl() + req.getMethod());
        Map<String, Object> map = new HashMap<>();
        map.put("result", true);
        List<Map<String, Object>> list = new ArrayList<>();
        for (int i = 1; i <= 5; i++) {
            Map<String, Object> u = new HashMap<>();
            u.put("uid", i);
            u.put("name", "李华");
            list.add(u);
        }
        map.put("data", list);
        String result = JSONObject.toJSONString(map);
        rep.fullWrite(result);
    }

    @Override
    public void init() {

    }

    @Override
    public void destory() {

    }
}
